$(function () {
    $(".key-box li").click(function () {
        var n = $(this).index();
        $("audio").stop().get(n).play();
        $(this).css("box-shadow", "none")
            .siblings().css("box-shadow", "10px 10px 20px black");
        $(".music-box li").eq(n).addClass("active").siblings().removeClass("active");
    })
    function play(index) {
        $("audio").get(index).play();
        $(".key-box li").eq(index).css("box-shadow", "none");
        $(".key-box li").eq(index).siblings().css("box-shadow", "10px 10px 20px black");
        $(".music-box li").eq(index).addClass("active").siblings().removeClass("active");
    }
    function stop(index) {
        $("audio").get(index).pause();
        $("audio").get(index).load();
    }
    //设置键盘控制
    $(document).keydown(function (event) {
        console.log(event.keyCode);
        if (event.keyCode == 97 || event.keyCode == 49) {
            play(0);
        }
        if (event.keyCode == 98 || event.keyCode == 50) {
            play(1);
        }
        if (event.keyCode == 99 || event.keyCode == 51) {
            play(2);
        }
        if (event.keyCode == 100 || event.keyCode == 52) {
            play(3);
        }
        if (event.keyCode == 101 || event.keyCode == 53) {
            play(4);
        }
        if (event.keyCode == 102 || event.keyCode == 54) {
            play(5);
        }
        if (event.keyCode == 103 || event.keyCode == 55) {
            play(6);
        }
        if (event.keyCode == 104 || event.keyCode == 56) {
            play(7);
        }

    })
    $(document).keyup(function (event) {
        console.log(event.keyCode);
        if (event.keyCode == 97 || event.keyCode == 49) {
            stop(0);
        }
        if (event.keyCode == 98 || event.keyCode == 50) {
            stop(1);
        }
        if (event.keyCode == 99 || event.keyCode == 51) {
            stop(2);
        }
        if (event.keyCode == 100 || event.keyCode == 52) {
            stop(3);
        }
        if (event.keyCode == 101 || event.keyCode == 53) {
            stop(4);
        }
        if (event.keyCode == 102 || event.keyCode == 54) {
            stop(5);
        }
        if (event.keyCode == 103 || event.keyCode == 55) {
            stop(6);
        }
        if (event.keyCode == 104 || event.keyCode == 56) {
            stop(7);
        }
    })
})